<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('订单列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<!-- Site wrapper -->
<div class="container-fluid mb-2">
    <div class="toolbar" id="toolbar" role="group">
        <form id="formId" class="form-inline">
            <input type="text" class="form-control mr-1" placeholder="id/订单号/手机号" name="searchKey"/>
            <select name="status" class="form-control mr-1">
                <option value="">状态</option>
                <option value="0">已配送</option>
                <option value="1">未配送</option>
            </select>
            <button type="button" class="btn btn-primary mr-1" onclick="$.table.search()">
                <i class="fa fa-search"></i> 搜索
            </button>
            <button type="button" class="btn btn-warning" onclick="$.form.reset()">
                <i class="fa fa-refresh"></i> 重置
            </button>
            <input type="hidden" name="userId" th:value="${userId}">
        </form>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <table id="bootstrap-table" class="table-striped"></table>
        </div>
    </div>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}"/>
<script th:inline="javascript">
    var prefix = "/order/express";
    $(function () {
        var options = {
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            url: prefix + "/list.json",
            modalName: "配送订单",
            columns: [
                {field: 'id', title: 'Id'},
                {field: 'orderNo',title: '订单号', formatter: function (value, row, index) {
                        return "<a href='javascript:void(0)' onclick=orderInfo('"+value+"')>"+value+"</a>";
                    }},
                {field: 'userName',title: '收件人'},
                {field: 'mobile', title: '联系电话'},
                {field: 'address', title: '配送地址'},
                {
                    field: 'status', title: '状态', formatter: function (value, row, index) {
                        if (row.status == 0) {
                            return '<span class="badge badge-danger">未配送</span>';
                        } else if (row.status == 1) {
                            return '<span class="badge badge-success">已配送</span>';
                        }
                    }
                },
                {field: 'courierNo', title: '快递单号'},
                {
                    title: '操作',
                    align: 'center',
                    width: '160px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick=expressInfo(\'' + row.id + '\')><i class="fa fa-search"></i>详情</a> ');
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick=expressEdit(\'' + row.id + '\')><i class="fa fa-edit"></i>修改</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //订单详情页
    function orderInfo(orderId) {
        var index = layer.open({
            title: '订单详情',
            content: "/order/view.html?id="+orderId,
            type: 2,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            area: ['95%','95%']
        });
    }

    //订单详情页
    function expressInfo(orderId) {
        var index = layer.open({
            title: '详情',
            content: prefix + "/view.html?id=" + orderId,
            type: 2,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            area: ['65%', '80%']
        });
    }

    function expressEdit(id) {
        $.modal.open("编辑",  prefix + "/edit.html?id=" + id, '800px', '380px');
    }
</script>
</body>
</html>